<style scoped lang='less'>
    .my-holiday-list {
        .action-cell {
            margin-bottom: 20px;
        }

        .home-list .search-block {
            display: flex;
            margin-bottom: 10px;
        }

        .input-search {
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .home-list .selected-search {
            height: 200px;
            width: 100%;
            position: relative;
            border-radius: 4px;
            margin-bottom: 10px;

        }

        .home-list .selected-search .search-action {
            position: absolute;
            top: 10px;
            left: 10px;
            right: 10px;
        }

        .home-list .selected-search .selected-arr {
            position: absolute;
            top: 50px;
            left: 20px;
            right: 20px;
            bottom: 10px;
            overflow: scroll;
        }

        .home-list .select-click {
            border: 1px solid #dddee1;
            border-radius: 4px;
            padding: 10px;
            font-weight: 500;
            text-align: center;
            width: 260px;
            margin-bottom: 10px;
        }

        .home-list .selected-search .selected-arr .selected-item {
            /*border-bottom: 1px solid #dfdfdf;*/
            margin-bottom: 10px;
            font-size: 15px;
        }
    }

</style>
<template>
    <div class="my-holiday-list">

        <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>

        <Modal v-model="setCheckIsShow" title="假条审核" @on-ok="handleSubmit('formValidate')"
               @on-cancel="setCheckIsShow =false">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110">
                <Form-item label="审核状态" prop="checkState">
                    <i-select v-model="formValidate.checkRet" placeholder="请选择审核状态">
                        <i-option value="true">通过</i-option>
                        <i-option value="false">拒绝</i-option>
                    </i-select>
                </Form-item>
                <template v-if="checkPeopleArr.length>0">
                    <Form-item label="下级审核员" prop="reason">
                        <Select v-model="checkSelection" prefix="md-search" style="width:200px">
                            <Option v-for="item in checkPeopleArr" :value="item.Id" :key="item.Id">{{ item.Displayname}}
                            </Option>
                        </Select>
                    </Form-item>
                </template>
                <template v-if="formValidate.checkRet == 'false'">
                    <Form-item label="拒绝原因" prop="reason">
                        <i-input v-model="formValidate.reason" placeholder="请输入拒绝原因"></i-input>
                    </Form-item>
                </template>
                <Form-item label="备注" prop="remark">
                    <i-input v-model="formValidate.remark" placeholder="请输入备注"></i-input>
                </Form-item>
                <!--<template v-else>-->
                <!--<Form-item label="选择允许通行门区" prop="gateInfos">-->
                <!--&lt;!&ndash;<Checkbox-group v-model="formValidate.gateInfos" @on-change="checkChangeGate">&ndash;&gt;-->
                <!--&lt;!&ndash;<Checkbox v-for="(item,index) in geteListArr" :value="item.Id" :key="index"&ndash;&gt;-->
                <!--&lt;!&ndash;:label="item.Gatename">&ndash;&gt;-->
                <!--&lt;!&ndash;{{item.Gatename}}&ndash;&gt;-->
                <!--&lt;!&ndash;</Checkbox>&ndash;&gt;-->
                <!--&lt;!&ndash;</Checkbox-group>&ndash;&gt;-->
                <!--<i-col span="12" >-->
                <!--<i-select  placeholder="选择允许通行门区" multiple  :model.sync="formValidate.gateInfos" filterable @on-change="checkChangeGate" >-->
                <!--<i-option  v-for="item in geteListArr" :value="item.Id">{{ item.Gatename }}</i-option>-->
                <!--</i-select>-->
                <!--</i-col>-->
                <!--</Form-item>-->
                <!--<Form-item label="通行类型" prop="crossType">-->
                <!--<i-select v-model="formValidate.crossType" placeholder="请选择审核状态">-->
                <!--<i-option value="单次进出">单次进出</i-option>-->
                <!--<i-option value="重复进出">重复进出</i-option>-->
                <!--</i-select>-->
                <!--</Form-item>-->
                <!--<Form-item label="通行的起始时间">-->
                <!--<Row>-->
                <!--<i-col span="11">-->
                <!--<Date-picker type="datetime" placeholder="选择开始日期"-->
                <!--@on-change="changeStartDate"></Date-picker>-->
                <!--</i-col>-->
                <!--</Row>-->
                <!--</Form-item>-->
                <!--<Form-item label="通行的结束时间">-->
                <!--<Row>-->
                <!--<i-col span="11">-->
                <!--<Date-picker type="datetime" placeholder="选择结束日期"-->
                <!--@on-change="changeEndDate"></Date-picker>-->
                <!--</i-col>-->
                <!--</Row>-->
                <!--</Form-item>-->
                <!--</template>-->
            </Form>
        </Modal>

    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import {Modal} from 'view-design';

    export default {
        data() {
            return {
                //审核
                setCheckIsShow: false,
                formValidate: {
                    checkRet: 'true',
                    remark: '',
                    reason: '',
                    nextCheckId: '',
                },
                geteListArr: [],
                ruleValidate: {},
                //审核人员
                checkPeopleArr: [],
                checkSelection: [],
                //表单
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                tableColumns: [
                    {
                        title: '请假人',
                        key: 'Displayname',
                        align: 'center',
                    },
                    {
                        title: '开始日期',
                        key: 'Startdate',
                        align: 'center',
                    },
                    {
                        title: '返回日期',
                        key: 'Enddate',
                        align: 'center',
                    },
                    {
                        title: '外出地址',
                        key: 'Destination',
                        align: 'center',
                    },
                    {
                        title: '请假原因',
                        key: 'Reason',
                        align: 'center',
                    },
                    {
                        title: '请假类型',
                        key: 'RestType',
                        align: 'center',
                    },
                    {
                        title: '审核状态',
                        key: 'State',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        'margin-right': '10px'
                                    },
                                    on: {
                                        click: () => {
                                            this.showCheckModal(params.row);
                                        }
                                    }
                                }, '审批'),
                            ])
                        }
                    }
                ]
            }
        },
        mounted() {
            let that = this;
            this.mockTableData();
        },
        component: {
            Modal
        },
        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            mockTableData() {
                let that = this;

                let para = {
                    id: sessionStorage.getItem('userId'),
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.RestCheckList, para, function (res) {
                    that.$Loading.finish();
                    that.tableData = res.Msg.Arrays;

                    console.log('tableData:', res)
                });
            },


            /**
             * 审核
             */


            //获取审核员列表
            getCheckerData(row) {
                let that = this;

                let para = {
                    // accountId: row.Accountid,
                    // restReqId: row.Id,
                    accountId: sessionStorage.getItem('userId'),
                    restReqId: row.Restreqid,
                    // startDate: '',
                    // endDate: '',
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.GetCheckerList, params, function (res) {
                    that.$Loading.finish();

                    that.checkPeopleArr = res.Msg;
                });
            },

            showCheckModal: function (row) {
                this.reqId = row.Restreqid;
                this.setCheckIsShow = true;
                this.getGateList();
                this.getCheckerData(row);
                console.log('假单ID：', row)
            },
            //选择门区
            checkChangeGate: function (data) {
                console.log('多选值:', data);
                let arr = Array.from(data);
                this.formValidate.gateInfos = arr.join();
                console.log('checkChangeGate:', this.formValidate.gateInfos)
            },
            changeStartDate: function (date) {
                this.formValidate.startDate = date;
            },
            changeEndDate: function (date) {
                this.formValidate.endDate = date;
            },
            //获取门区信息
            getGateList() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GateServerList, para, function (res) {
                    that.$Loading.finish();

                    that.geteListArr = res.Msg;

                });
            },
            handleSubmit(name) {
                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.EditRestToState(model);
                })
            },
            EditRestToState(model) {
                let that = this;

                if (model.checkRet == 'false') {
                    model.endDate = '2000-10-16';
                    model.startDate = '2000-10-11';
                }
                model.requestId = this.reqId;
                model.nextCheckId = this.checkSelection;
                model.checkerId = sessionStorage.getItem('userId');
                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.ChangeCheckState, params, function (res) {
                    that.$Loading.finish();
                    that.$Message.info('成功 ');
                    that.mockTableData();
                });

            },
        },
    }
</script>
